@echo off
:: Set Python version and installer file name
set PYTHON_VERSION=3.11.0
set INSTALLER_NAME=python-%PYTHON_VERSION%-amd64.exe
set DOWNLOAD_URL=https://www.python.org/ftp/python/%PYTHON_VERSION%/%INSTALLER_NAME%

:: Check if the Python installer already exists in the Downloads folder
echo Checking if Python %PYTHON_VERSION% installer already exists...
if exist "%USERPROFILE%\Downloads\%INSTALLER_NAME%" (
    echo Installer already exists. Skipping download.
) else (
    echo Downloading Python %PYTHON_VERSION% installer...
    powershell -Command "Invoke-WebRequest -Uri '%DOWNLOAD_URL%' -OutFile '%USERPROFILE%\Downloads\%INSTALLER_NAME%'"
    if errorlevel 1 (
        echo Download failed. Please check your internet connection or the download URL.
        pause
        exit /b
    )
)

:: Launch the Python installer
echo Starting Python %PYTHON_VERSION% installer...
start "" "%USERPROFILE%\Downloads\%INSTALLER_NAME%"

echo Python %PYTHON_VERSION% installer has been launched. Please follow the on-screen instructions to complete the installation.
echo Press any key to continue after installation is complete...
pause >nul

:: Verify Python installation, maybe need restart before verify successfully
echo Verifying Python installation...
python --version
if errorlevel 1 (
    echo Python installation failed. Please check the installation process.
) else (
    echo Python has been successfully installed!
)

pause